package com.jpcc.vw.onlineRadio.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.jpcc.vw.onlineRadio.adapter.item.LocalOnlineRadioInfoItem;
import com.jpcc.vw.onlineRadio.model.bean.LocalOnlineRadioEntity;
import com.jpcc.vw.onlineRadio.recycle.RecyclerView.BaseItem;
import com.jpcc.vw.onlineRadio.recycle.RecyclerView.MultiTypeListAdapter;

import java.util.ArrayList;
import java.util.List;

public class LocalOnlineRadioInfoAdapter extends MultiTypeListAdapter<LocalOnlineRadioEntity> {


    private List<LocalOnlineRadioEntity> datas = new ArrayList<>();
    private Context mContext;

    public LocalOnlineRadioInfoAdapter(Context c, List<LocalOnlineRadioEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            mContext = c;
        }
    }

    @Override
    public LocalOnlineRadioEntity getItem(int viewType, int position) {
        return datas.get(position);
    }

    @Override
    public BaseItem<LocalOnlineRadioEntity> createItemView(ViewGroup parent, int viewType) {
        return new LocalOnlineRadioInfoItem(parent);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    public void setDatas(List<LocalOnlineRadioEntity> sources){
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            notifyDataSetChanged();
        }
    }
}
